
package com.atcc.test.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import com.atcc.test.pojo.User;

@RestController
public class UserController {
	
	@Autowired
	private RestTemplate restTemplate;
	
	//private static final String BASIC_URL = "http://localhost:8001";
	private static final String BASIC_URL = "http://PROVIDER-x001";
	
	@SuppressWarnings("unchecked")
	@GetMapping("/consumer/test")
	public List<User> getAll() {
		String requestUrl = BASIC_URL+"/test";
		return restTemplate.getForObject(requestUrl,List.class);
	}
	
	@GetMapping("/consumer/test/{id}")
	public User getUserById(@PathVariable("id") long id) {
		String requestUrl = BASIC_URL+"/test/"+id;
		return restTemplate.getForObject(requestUrl,User.class);
	}

}
